package tenthwork.one;

import java.util.*;

/**
 * @author ：chenzikang
 * @date ： 2020/4/21
 */

public class ManageSystem {


    Student student = new Student();
    List<Student> lists = new ArrayList();
    Scanner scanner = new Scanner(System.in);


    public ManageSystem() {

    }


    // 添加一个学生对象
    public void add() {
         student = new Student();

        System.out.print("输入学号: ");
        student.setId(scanner.next());

        System.out.print("输入姓名: ");
        student.setName(scanner.next());

        System.out.print("输入年龄: ");
        student.setAge(scanner.nextInt());

        System.out.print("输入高数成绩: ");
        student.setHighMathScore(scanner.nextDouble());

        System.out.print("输入数据结构成绩: ");
        student.setDataObjectScore(scanner.nextDouble());

        System.out.print("输入英语成绩: ");
        student.setEnglishScore(scanner.nextDouble());

        System.out.print("输入大物成绩: ");
        student.setCollegePhysics(scanner.nextDouble());

        System.out.print("输入马哲成绩: ");
        student.setMarxismScore(scanner.nextDouble());

        student.setTotalScore(0.5 * student.getHighMathScore() + 0.4 * student.getDataObjectScore()
                +0.5*student.getEnglishScore()+0.2*student.getCollegePhysics()+0.1*student.getMarxismScore());

        lists.add(student);
    }

    // 列出所有学生对象
    public void list() {
        for (Student list : lists) {
            System.out.println(list.toString());
        }
    }

    public void result(String name) {

        for (int i = 0; i < lists.size(); i++) {
            Student s = lists.get(i);
            if (name.equals(s.getName())) {

               System.out.println("平均成绩为:"+s.getTotalScore());

            }


        }

    }

     //根据姓名来查找一个对象
    public Student find( String name)
    {
        for (int i = 0; i< lists.size(); i++)
        {
            Student s =  lists.get(i);

            if(name.equals( s.getName()))
            {
                return s;
            }
        }
        return null;
    }

    public void ranking(){
        List<Double> newRank = new ArrayList<>();
        for (int i = 0; i < lists.size() ; i++) {
            Student s =  lists.get(i);

            newRank.add(s.getTotalScore());

        }
        Collections.sort(newRank);

        System.out.println(newRank.toString());



    }

    // 删除
    public void remove(String id) {
        lists.remove(id);
    }
}
